<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //定义一个json对象
        var jsonObj = {
            "name":'张三',
            "age":'18',
            "gender":'男',
            "hobby":['足球','篮球','羽毛球'],
            "action":function(){
                console.log('json中的方法')
            }
        }
        console.log(jsonObj.name);
        console.log(jsonObj.age);
        console.log(jsonObj.hobby[0]);
        // 定义json字符串
        var jsonStr = '{"name":"Tom", "age":18, "addr":["北京","上海","西安"]}';
        console.log(jsonStr);
        //json字符串 --> json对象
        var obj = JSON.parse(jsonStr);
        console.log(obj);
        console.log(obj.name);
        //json对象 --> json字符串
        var jsonStr2 = JSON.stringify(obj);
        console.log(jsonStr2);
    </script>
</body>
</html>